﻿using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Text;
using netDxf;
using netDxf.Blocks;
using netDxf.Collections;
using netDxf.Entities;
using netDxf.Header;
using netDxf.Objects;
using netDxf.Tables;
using netDxf.Units;
using Attribute = netDxf.Entities.Attribute;
using Image = netDxf.Entities.Image;
using Point = netDxf.Entities.Point;
using Trace = netDxf.Entities.Trace;
using System.Threading;

namespace TestDxfDocument
{

    class _Shellendmills
    {
        public static void  Shellendmills(Dictionary<string, Object> data)  //套式铰刀
        {
            DxfDocument dxf = new DxfDocument();
            //图层
            Layer contour = new Layer("contour") { Color = AciColor.Cyan };    //轮廓层
            Layer dimensioning = new Layer("dimensioning");    //尺寸层
            Layer refin = new Layer("refin") { Color = AciColor.Red };    //基准线/内轮廓
            Layer centre = new Layer("centre") { Color = AciColor.Yellow };    //中心线
            Layer textlayer = new Layer("textlayer") { Color = AciColor.Blue };    //文本层
            Layer hatching = new Layer("hatching") { Color = AciColor.Blue };    //填充层
            Layer additionalline = new Layer("additionalline") { Color = AciColor.Cyan };    //附加线
            Layer cutting = new Layer("cutting") { Color = AciColor.Red };    //切削层
            Layer nocutting = new Layer("nocutting");    //非切削层
            Layer skcontour = new Layer("skcontour") { Color = AciColor.Cyan };    //sk轮廓层
            Layer skdimensioning = new Layer("skdimensioning");    //sk尺寸线层
            Layer skrefin = new Layer("skrefin") { Color = AciColor.Red };    //sk基准线/内轮廓
            Layer sktext = new Layer("sktext") { Color = AciColor.Blue };    //sk文本
            Layer skhatching = new Layer("skhatching") { Color = AciColor.Blue };    //sk填充
            Layer skadditionlline = new Layer("skadditionlline") { Color = AciColor.Cyan };    //sk附加线
            Layer skviewcontour = new Layer("skviewcontour") { Color = AciColor.Cyan };    //skview轮廓
            Layer skviewdimensioning = new Layer("skviewdimensioning");    //skview尺寸线层
            //作图
            //参数
            double pi = Math.PI;
            string path = Convert.ToString(data["path"]);

            double dc = Convert.ToDouble(data["dc"]);
            double d =  Convert.ToDouble(data["ccms"]);
            double oal =  Convert.ToDouble(data["cw"]);
            double l = Convert.ToDouble(data["lccb"]);
            double d1 =  Convert.ToDouble(data["dccb"]);
            double d2 =  Convert.ToDouble(data["dhub"]);

            Vector2 v1 = new Vector2(0, 0);
            Vector2 v2 = new Vector2(v1.X + oal + 6, v1.Y);
            Vector2 v3 = new Vector2(v1.X + 3, v1.Y);
            Vector2 v4 = new Vector2(v3.X, v3.Y + d2 / 2);
            Vector2 v5 = new Vector2(v4.X + 0.5, v4.Y + 0.5);
            Vector2 v6 = new Vector2(v5.X, v3.Y + dc / 2);
            Vector2 v7 = new Vector2(v3.X + oal, v6.Y);
            Vector2 v8 = new Vector2(v7.X, v3.Y + dc * 4.17 / 28.52);
            Vector2 v9 = new Vector2(v8.X, v3.Y + dc * 5.89 / 28.52);
            Vector2 v10 = new Vector2(v9.X - oal * 1.18 / 16.92, v9.Y);
            Vector2 v11 = new Vector2(v9.X - oal * 1.33 / 16.92, v9.Y - dc * 0.5 / 28.52);
            Vector2 v12 = new Vector2(v8.X, v3.Y);
            Vector2 v13 = new Vector2(v12.X, v12.Y - dc * 0.77 / 28.52);
            Vector2 v14 = new Vector2(v13.X - oal * 1.64 / 16.92, v13.Y - dc * 3.33 / 28.52);
            Vector2 v15 = new Vector2(v14.X - oal * 2.41 / 16.92, v14.Y - dc * 1.83 / 28.52);
            Vector2 v16 = new Vector2(v15.X, v15.Y - dc * 0.47 / 28.52);
            Vector2 v17 = new Vector2(v8.X, v16.Y);
            Vector2 v20 = new Vector2(v6.X, v6.Y * -1);
            Vector2 v19 = new Vector2(v20.X + oal * 15.23 / 16.92, v20.Y + dc * 2.08 / 28.52);
            Vector2 v18 = new Vector2(v17.X, v19.Y + dc * 1.37 / 28.52);
            Vector2 v21 = new Vector2(v5.X, v5.Y * -1);
            Vector2 v22 = new Vector2(v4.X, v21.Y);
            Vector2 v23 = new Vector2(v11.X + (dc * 2.06 / 28.52) * (v12.X - v11.X) / (v11.Y - v12.Y), v11.Y - (dc * 2.06 / 28.52));
            Vector2 v24 = new Vector2(v13.X - oal * 3.66 / 16.92, v13.Y);
            Vector2 v25 = new Vector2(v24.X - (v12.Y - v13.Y), v12.Y);
            Vector2 v26 = new Vector2(v19.X, v19.Y +(dc-d1)/2*3.04/8.133);
            Vector2 v27 = new Vector2(v3.X + l, v3.Y - d1 / 2);
            Vector2 v28 = new Vector2(v27.X, v3.Y);
            Vector2 v29 = new Vector2(v27.X, v3.Y - d1 / 2 * 5.07 / 5.97);
            Vector2 v30 = new Vector2(v3.X, v29.Y);
            Vector2 v32 = new Vector2(v27.X + (oal - l) / 2, v27.Y - (oal - l) / 2 * (v27.Y - v26.Y) / (v26.X - v27.X));
            Vector2 v31 = new Vector2(v32.X - (oal - l) * 0.41 / 8.17, v21.Y);
            Vector2 v33 = new Vector2(v6.X, v6.Y - (dc - d2) / 2 * 1.71 / 6.63);
            Vector2 v34 = new Vector2(v7.X, v7.Y - (v7.X - v6.X) * (v4.Y - v11.Y) / (v11.X - v4.X));
            Vector2 v35 = new Vector2(v10.X, v34.Y + (v7.Y - v34.Y) * 1.47 / 4.44);
            Vector2 v36 = new Vector2(v30.X, v30.Y * -1);
            Vector2 v37 = new Vector2(v5.X + oal * 12.01 / 16.92, v5.Y);
            Vector2 v38 = new Vector2(v37.X + oal * 0.38 / 16.92, v37.Y - (dc - d2 ) / 2 * 1.56 / 10.27);
            Vector2 v39 = new Vector2(v28.X, v36.Y + (dc - d2) / 2 * 0.75 / 10.27);
            Vector2 v40 = new Vector2(v28.X, v36.Y);

            Vector2 v41 = new Vector2(v2.X + dc / 2, v2.Y);
            Vector2 v42 = new Vector2(v41.X + dc + 6, v41.Y);
            Vector2 v43 = new Vector2(v41.X + dc / 2 + 3, v41.Y);
            Vector2 v44 = new Vector2(v43.X, v43.Y + dc / 2 + 3);
            Vector2 v45 = new Vector2(v44.X, v44.Y * -1);
            Vector2 v46 = new Vector2(v43.X, v7.Y);
            Vector2 v47 = new Vector2(v46.X + dc / 2 * 0.53 / 15.34, v33.Y);
            Vector2 v48 = new Vector2(v46.X - dc / 2 * 0.63 / 15.34, v46.Y - (dc - d2) / 2 * 3.71 / 6.11);
            Vector2 v49 = new Vector2(v46.X - dc / 2 * 2.84 / 15.34, v46.Y - (dc - d2) / 2 * 4.26 / 6.11);
            Vector2 v50 = new Vector2(v46.X - dc / 2 * 3.95 / 15.34, v46.Y - (dc - d2) / 2 * 0.53 / 6.11);
            Vector2 v51 = fun.rotatePoint_Changed(v43, v48, -45);
            Vector2 v52 = fun.rotatePoint_Changed(v43, v46, -45);
            Vector2 v53 = fun.rotatePoint_Changed(v43, v50, -45);
            Vector2 v54 = fun.rotatePoint_Changed(v43, v49, -45);
            Vector2 v55 = fun.rotatePoint_Changed(v43, v47, -45);
            Vector2 v56 = fun.rotatePoint_Changed(v43, v51, -45);
            Vector2 v57 = fun.rotatePoint_Changed(v43, v52, -45);
            Vector2 v58 = fun.rotatePoint_Changed(v43, v53, -45);
            Vector2 v59 = fun.rotatePoint_Changed(v43, v54, -45);
            Vector2 v60 = fun.rotatePoint_Changed(v43, v55, -45);
            Vector2 v61 = fun.rotatePoint_Changed(v43, v56, -45);
            Vector2 v62 = fun.rotatePoint_Changed(v43, v57, -45);
            Vector2 v63 = fun.rotatePoint_Changed(v43, v58, -45);
            Vector2 v64 = fun.rotatePoint_Changed(v43, v59, -45);
            Vector2 v65 = fun.rotatePoint_Changed(v43, v60, -45);
            Vector2 v66 = fun.rotatePoint_Changed(v43, v61, -45);
            Vector2 v67 = fun.rotatePoint_Changed(v43, v62, -45);
            Vector2 v68 = fun.rotatePoint_Changed(v43, v63, -45);
            Vector2 v69 = fun.rotatePoint_Changed(v43, v64, -45);
            Vector2 v70 = fun.rotatePoint_Changed(v43, v65, -45);
            Vector2 v71 = fun.rotatePoint_Changed(v43, v66, -45);
            Vector2 v72 = fun.rotatePoint_Changed(v43, v67, -45);
            Vector2 v73 = fun.rotatePoint_Changed(v43, v68, -45);
            Vector2 v74 = fun.rotatePoint_Changed(v43, v69, -45);
            Vector2 v75 = fun.rotatePoint_Changed(v43, v70, -45);
            Vector2 v76 = fun.rotatePoint_Changed(v43, v71, -45);
            Vector2 v77 = fun.rotatePoint_Changed(v43, v72, -45);
            Vector2 v78 = fun.rotatePoint_Changed(v43, v73, -45);
            Vector2 v79 = fun.rotatePoint_Changed(v43, v74, -45);
            Vector2 v80 = fun.rotatePoint_Changed(v43, v75, -45);
            Vector2 v81 = fun.rotatePoint_Changed(v43, v76, -45);
            Vector2 v82 = fun.rotatePoint_Changed(v43, v77, -45);
            Vector2 v83 = fun.rotatePoint_Changed(v43, v78, -45);
            Vector2 v84 = fun.rotatePoint_Changed(v43, v79, -45);
            Vector2 v85 = fun.rotatePoint_Changed(v43, v80, -45);
            Vector2 v86 = new Vector2(v43.X, v43.Y + d1 / 2);
            Vector2 v87 = new Vector2(v43.X + d1 / 2, v43.Y);
            Vector2 v88 = new Vector2(v86.X, v86.Y * -1);
            Vector2 v89 = new Vector2(v43.X - d1 / 2, v43.Y);
            Vector2 a59 = new Vector2(v59.X - dc, v59.Y);
            Vector2 a79 = new Vector2(v79.X + dc, v79.Y);

            //作图
            Line line1 = new Line(v1, v2);
            line1.Layer = centre;
            line1.Linetype = Linetype.DashDot;
            line1.LinetypeScale = 3;
            dxf.AddEntity(line1);

            LwPolyline line2 = new LwPolyline();
            line2.Vertexes.Add(new LwPolylineVertex(v4));
            line2.Vertexes.Add(new LwPolylineVertex(v5));
            line2.Vertexes.Add(new LwPolylineVertex(v6));
            line2.Vertexes.Add(new LwPolylineVertex(v7));
            line2.Vertexes.Add(new LwPolylineVertex(v9));
            line2.Vertexes.Add(new LwPolylineVertex(v10));
            line2.Vertexes.Add(new LwPolylineVertex(v11));
            line2.Vertexes.Add(new LwPolylineVertex(v12));
            line2.Vertexes.Add(new LwPolylineVertex(v13));
            line2.Vertexes.Add(new LwPolylineVertex(v14));
            line2.Vertexes.Add(new LwPolylineVertex(v15));
            line2.Vertexes.Add(new LwPolylineVertex(v16));
            line2.Vertexes.Add(new LwPolylineVertex(v17));
            line2.Vertexes.Add(new LwPolylineVertex(v18));
            line2.Vertexes.Add(new LwPolylineVertex(v19));
            line2.Vertexes.Add(new LwPolylineVertex(v20));
            line2.Vertexes.Add(new LwPolylineVertex(v21));
            line2.Vertexes.Add(new LwPolylineVertex(v22));
            line2.Vertexes[5].Bulge = Math.Tan(105 * pi / 180 / 4);
            fun.PolyFill(dxf, line2, 0.1, contour);

            LwPolyline line3 = new LwPolyline();
            line3.Vertexes.Add(new LwPolylineVertex(v9));
            line3.Vertexes.Add(new LwPolylineVertex(v8));
            line3.Vertexes.Add(new LwPolylineVertex(v23));
            line3.Vertexes[1].Bulge = Math.Tan(-72 * pi / 180 / 4);
            fun.PolyFill(dxf, line3, 0.1, contour);

            LwPolyline line4 = new LwPolyline();
            line4.Vertexes.Add(new LwPolylineVertex(v13));
            line4.Vertexes.Add(new LwPolylineVertex(v24));
            line4.Vertexes.Add(new LwPolylineVertex(v25));
            line4.Vertexes[1].Bulge = Math.Tan(-90 * pi / 180 / 4);
            fun.PolyFill(dxf, line4, 0.1, contour);

            LwPolyline line5 = new LwPolyline();
            line5.Vertexes.Add(new LwPolylineVertex(v19));
            line5.Vertexes.Add(new LwPolylineVertex(v26));
            line5.Vertexes.Add(new LwPolylineVertex(v17));
            line5.Vertexes.Add(new LwPolylineVertex(v26));
            line5.Vertexes.Add(new LwPolylineVertex(v27));
            line5.Vertexes.Add(new LwPolylineVertex(v28));
            line5.Vertexes.Add(new LwPolylineVertex(v29));
            line5.Vertexes.Add(new LwPolylineVertex(v30));
            fun.PolyFill(dxf, line5, 0.1, contour);

            LwPolyline line6 = new LwPolyline();
            line6.Vertexes.Add(new LwPolylineVertex(v21));
            line6.Vertexes.Add(new LwPolylineVertex(v31));
            line6.Vertexes.Add(new LwPolylineVertex(v32));
            fun.PolyFill(dxf, line6, 0.1, contour);

            LwPolyline line7 = new LwPolyline();
            line7.Vertexes.Add(new LwPolylineVertex(v34));
            line7.Vertexes.Add(new LwPolylineVertex(v33));
            line7.Vertexes.Add(new LwPolylineVertex(v35));
            line7.Vertexes.Add(new LwPolylineVertex(v34));
            fun.PolyFill(dxf, line7, 0.1, contour);

            LwPolyline line8 = new LwPolyline();
            line8.Vertexes.Add(new LwPolylineVertex(v11));
            line8.Vertexes.Add(new LwPolylineVertex(v4));
            fun.PolyFill(dxf, line8, 0.1, contour);

            LwPolyline line9 = new LwPolyline();
            line9.Vertexes.Add(new LwPolylineVertex(v36));
            line9.Vertexes.Add(new LwPolylineVertex(v12));
            fun.PolyFill(dxf, line9, 0.1, contour);

            Line line10 = new Line(v5, v37);
            line10.Layer = refin;
            line10.Linetype = Linetype.Dashed;
            line10.LinetypeScale = 3;
            dxf.AddEntity(line10);

            Line line11 = new Line(v38, v37);
            line11.Layer = refin;
            line11.Linetype = Linetype.Dashed;
            line11.LinetypeScale = 3;
            dxf.AddEntity(line11);

            Line line12 = new Line(v38, v5);
            line12.Layer = refin;
            line12.Linetype = Linetype.Dashed;
            line12.LinetypeScale = 3;
            dxf.AddEntity(line12);

            Line line13 = new Line(v38, v39);
            line13.Layer = refin;
            line13.Linetype = Linetype.Dashed;
            line13.LinetypeScale = 3;
            dxf.AddEntity(line13);

            Line line14 = new Line(v28, v39);
            line14.Layer = refin;
            line14.Linetype = Linetype.Dashed;
            line14.LinetypeScale = 3;
            dxf.AddEntity(line14);

            Line line15 = new Line(v36, v40);
            line15.Layer = refin;
            line15.Linetype = Linetype.Dashed;
            line15.LinetypeScale = 3;
            dxf.AddEntity(line15);

            Line line16 = new Line(v41, v42);
            line16.Layer = centre;
            line16.Linetype = Linetype.DashDot;
            line16.LinetypeScale = 3;
            dxf.AddEntity(line16);

            Line line17 = new Line(v44, v45);
            line17.Layer = centre;
            line17.Linetype = Linetype.DashDot;
            line17.LinetypeScale = 3;
            dxf.AddEntity(line17);

            LwPolyline line18 = new LwPolyline();
            line18.Vertexes.Add(new LwPolylineVertex(v48));
            line18.Vertexes.Add(new LwPolylineVertex(v46));
            line18.Vertexes.Add(new LwPolylineVertex(v50));
            line18.Vertexes.Add(new LwPolylineVertex(v49));
            line18.Vertexes.Add(new LwPolylineVertex(v48));
            line18.Vertexes.Add(new LwPolylineVertex(v47));
            line18.Vertexes.Add(new LwPolylineVertex(v53));
            line18.Vertexes[3].Bulge = Math.Tan(93 * pi / 180 / 4);
            fun.PolyFill(dxf, line18, 0.1, contour);

            LwPolyline line19 = new LwPolyline();
            line19.Vertexes.Add(new LwPolylineVertex(v51));
            line19.Vertexes.Add(new LwPolylineVertex(v52));
            line19.Vertexes.Add(new LwPolylineVertex(v53));
            line19.Vertexes.Add(new LwPolylineVertex(v54));
            line19.Vertexes.Add(new LwPolylineVertex(v51));
            line19.Vertexes.Add(new LwPolylineVertex(v55));
            line19.Vertexes.Add(new LwPolylineVertex(v58));
            line19.Vertexes[3].Bulge = Math.Tan(93 * pi / 180 / 4);
            fun.PolyFill(dxf, line19, 0.1, contour);

            LwPolyline line20 = new LwPolyline();
            line20.Vertexes.Add(new LwPolylineVertex(v56));
            line20.Vertexes.Add(new LwPolylineVertex(v57));
            line20.Vertexes.Add(new LwPolylineVertex(v58));
            line20.Vertexes.Add(new LwPolylineVertex(v59));
            line20.Vertexes.Add(new LwPolylineVertex(v56));
            line20.Vertexes.Add(new LwPolylineVertex(v60));
            line20.Vertexes.Add(new LwPolylineVertex(v63));
            line20.Vertexes[3].Bulge = Math.Tan(93 * pi / 180 / 4);
            fun.PolyFill(dxf, line20, 0.1, contour);

            LwPolyline line21 = new LwPolyline();
            line21.Vertexes.Add(new LwPolylineVertex(v61));
            line21.Vertexes.Add(new LwPolylineVertex(v62));
            line21.Vertexes.Add(new LwPolylineVertex(v63));
            line21.Vertexes.Add(new LwPolylineVertex(v64));
            line21.Vertexes.Add(new LwPolylineVertex(v61));
            line21.Vertexes.Add(new LwPolylineVertex(v65));
            line21.Vertexes.Add(new LwPolylineVertex(v68));
            line21.Vertexes[3].Bulge = Math.Tan(93 * pi / 180 / 4);
            fun.PolyFill(dxf, line21, 0.1, contour);

            LwPolyline line22 = new LwPolyline();
            line22.Vertexes.Add(new LwPolylineVertex(v66));
            line22.Vertexes.Add(new LwPolylineVertex(v67));
            line22.Vertexes.Add(new LwPolylineVertex(v68));
            line22.Vertexes.Add(new LwPolylineVertex(v69));
            line22.Vertexes.Add(new LwPolylineVertex(v66));
            line22.Vertexes.Add(new LwPolylineVertex(v70));
            line22.Vertexes.Add(new LwPolylineVertex(v73));
            line22.Vertexes[3].Bulge = Math.Tan(93 * pi / 180 / 4);
            fun.PolyFill(dxf, line22, 0.1, contour);

            LwPolyline line23 = new LwPolyline();
            line23.Vertexes.Add(new LwPolylineVertex(v71));
            line23.Vertexes.Add(new LwPolylineVertex(v72));
            line23.Vertexes.Add(new LwPolylineVertex(v73));
            line23.Vertexes.Add(new LwPolylineVertex(v74));
            line23.Vertexes.Add(new LwPolylineVertex(v71));
            line23.Vertexes.Add(new LwPolylineVertex(v75));
            line23.Vertexes.Add(new LwPolylineVertex(v78));
            line23.Vertexes[3].Bulge = Math.Tan(93 * pi / 180 / 4);
            fun.PolyFill(dxf, line23, 0.1, contour);

            LwPolyline line24 = new LwPolyline();
            line24.Vertexes.Add(new LwPolylineVertex(v76));
            line24.Vertexes.Add(new LwPolylineVertex(v77));
            line24.Vertexes.Add(new LwPolylineVertex(v78));
            line24.Vertexes.Add(new LwPolylineVertex(v79));
            line24.Vertexes.Add(new LwPolylineVertex(v76));
            line24.Vertexes.Add(new LwPolylineVertex(v80));
            line24.Vertexes.Add(new LwPolylineVertex(v83));
            line24.Vertexes[3].Bulge = Math.Tan(93 * pi / 180 / 4);
            fun.PolyFill(dxf, line24, 0.1, contour);

            LwPolyline line25 = new LwPolyline();
            line25.Vertexes.Add(new LwPolylineVertex(v81));
            line25.Vertexes.Add(new LwPolylineVertex(v82));
            line25.Vertexes.Add(new LwPolylineVertex(v83));
            line25.Vertexes.Add(new LwPolylineVertex(v84));
            line25.Vertexes.Add(new LwPolylineVertex(v81));
            line25.Vertexes.Add(new LwPolylineVertex(v85));
            line25.Vertexes.Add(new LwPolylineVertex(v50));
            line25.Vertexes[3].Bulge = Math.Tan(93 * pi / 180 / 4);
            fun.PolyFill(dxf, line25, 0.1, contour);

            fun.drawcircle(dxf, v43, d2 / 2, 0.1, contour);


            Arc arc1 = fun.DrawArc3(v88, v87, v86);
            fun.drawBArc(dxf, arc1, 0.1, contour);

            Arc arc2 = fun.DrawArc3(v86, v89, v88);
            fun.drawBArc(dxf, arc2, 0.1, contour);

            Vector2 v90 = fun.getPointForArcandLine(v59, a59, v43, arc1);
            Vector2 v91 = fun.getPointForArcandLine(v59, a59, v43, arc2);
            Vector2 v92 = fun.Inters(v83, v80, a59, v59);
            Vector2 v93= fun.getPointForArcandLine(v79, a79, v43, arc2);
            Vector2 v94 = fun.getPointForArcandLine(v79, a79, v43, arc1);
            Vector2 v95 = fun.Inters(v63, v60, a79, v79);

            LwPolyline line26 = new LwPolyline();
            line26.Vertexes.Add(new LwPolylineVertex(v59));
            line26.Vertexes.Add(new LwPolylineVertex(v91));
            fun.PolyFill(dxf, line26, 0.1, contour);

            LwPolyline line27 = new LwPolyline();
            line27.Vertexes.Add(new LwPolylineVertex(v90));
            line27.Vertexes.Add(new LwPolylineVertex(v92));
            fun.PolyFill(dxf, line27, 0.1, contour);

            LwPolyline line28 = new LwPolyline();
            line28.Vertexes.Add(new LwPolylineVertex(v94));
            line28.Vertexes.Add(new LwPolylineVertex(v79));
            fun.PolyFill(dxf, line28, 0.1, contour);

            LwPolyline line29 = new LwPolyline();
            line29.Vertexes.Add(new LwPolylineVertex(v95));
            line29.Vertexes.Add(new LwPolylineVertex(v93));
            fun.PolyFill(dxf, line29, 0.1, contour);

            Vector2 v96 = new Vector2(v3.X, v92.Y);
            Vector2 v97 = new Vector2(v96.X + oal * 2.66 / 16.92, v96.Y);
            Vector2 v98 = new Vector2(v97.X, v97.Y * -1);
            Vector2 v99 = new Vector2(v96.X, v98.Y);

            LwPolyline line30 = new LwPolyline();
            line30.Vertexes.Add(new LwPolylineVertex(v4));
            line30.Vertexes.Add(new LwPolylineVertex(v96));
            line30.Vertexes.Add(new LwPolylineVertex(v97));
            line30.Vertexes.Add(new LwPolylineVertex(v98));
            line30.Vertexes.Add(new LwPolylineVertex(v99));
            line30.Vertexes.Add(new LwPolylineVertex(v22));
            fun.PolyFill(dxf, line30, 0.1, contour);

            //标注

            double height = 2;
            double arrowsize = 2;
            double exline = 2;


            fun.dimrot1(dxf, v4, new Vector2 (v4.X ,v4.Y *-1), 90, d2/2, 1, height, arrowsize, exline, "d2=" + d2, "", "");

            fun.dimrot1(dxf, v6, v20, 90, d2, 1, height, arrowsize, exline, "D=" + dc, "", "");

            fun.dimrot1(dxf, v22, v27, 180, d, 1, height, arrowsize, exline, "l=" + l, "", "");

            fun.dimrot1(dxf, v22, v18, 180, d*1.5, 1, height, arrowsize, exline, "L=" + oal, "", "");

            fun.dimrot1(dxf, v89, v87, 180, 0, 1, height, arrowsize, exline, "d=" + d, "", "");


            double isframe = Convert.ToInt32(data["isframe"]);
            String isframe_chose = Convert.ToString(data["isframe_chose"]);
            double scale = Convert.ToDouble(data["scale"]); //放大系数
            Vector2 p0 = new Vector2(0, 0);
            if (isframe == 1)
            {
                if (isframe_chose.Equals("0"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA0X(dxf, new Vector2(p0.X - 1189 / 2.0, p0.Y + 841 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("1"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA1X(dxf, new Vector2(p0.X - 841 / 2.0, p0.Y + 594 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("2"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA2X(dxf, new Vector2(p0.X - 594 / 2.0, p0.Y + 420 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("3"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA3X(dxf, new Vector2(p0.X - 420 / 2.0, p0.Y + 297 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("4X"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA4X(dxf, new Vector2(p0.X - 297 / 2.0, p0.Y + 210 / 2.0 - 10 * 2.26), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }

                if (isframe_chose.Equals("4Y"))
                {
                    Dictionary<string, Vector2> position = Frame.frameA4Y(dxf, new Vector2(p0.X - 210 / 2.0, p0.Y + 297 / 2.0), data);
                    fun.writetext(dxf, scale + ":1", position["比例"], 3.5, 0, 0.6, "C");
                }
            }


            //定义格式，根据路径导出
            dxf.DrawingVariables.AcadVer = DxfVersion.AutoCad2007;
            dxf.Save(path);
        }

    }
}
